//main.js
angular
.module('zhserverApp')
.controller('cardChartCtrl1', cardChartCtrl1)
cardChartCtrl1.$inject = ['$scope','D_m_zhenghe_doctor_stat','D_m_zhenghe_doctor_expr_stat','D_m_zhenghe_user_stat','D_m_zhenghe_recipe_stat','D_m_zhenghe_seekrecipe_stat','D_m_zhenghe_act_user_stat'];
function cardChartCtrl1($scope,D_m_zhenghe_doctor_stat,D_m_zhenghe_doctor_expr_stat,D_m_zhenghe_user_stat,D_m_zhenghe_recipe_stat,D_m_zhenghe_seekrecipe_stat,D_m_zhenghe_act_user_stat) {

    $scope.options = {
        scales: {
            yAxes: [{
                ticks: {
                    min: 0
                    // stepSize: 1
                }
            }],
        },
        legend: {
            display: true,
            labels: {
                fontColor: '#999'
            }
        }
    };
  //医生总量 start
    $scope.d_m_zhenghe_doctor_stats = [];
    $scope.labels1=[];
    $scope.data1=[
        [],
        []
    ];
    $scope.series1 = ['注册数量', '活跃量'];
    get1();

    function get1() {
        D_m_zhenghe_doctor_stat.query(function(result) {
            $scope.d_m_zhenghe_doctor_stats = result;
            angular.forEach($scope.d_m_zhenghe_doctor_stats,function (data,index) {
                $scope.labels1[index]= data.hosp_name;
                $scope.data1[0][index]=data.reg_doctors;
                $scope.data1[1][index]=data.act_doctors;
            });
        });
    }

    //医生总量 end

    //医生临床经验 start
    $scope.d_m_zhenghe_doctor_expr_stats = [];
    $scope.labels2=[];
    $scope.data2=[
        [],
        [],
        [],
        [],
        []
    ];
    $scope.series2 = ['1-5年', '5-10年','10-20年','20-30年','30年以上'];
    get2();

    function get2() {
        D_m_zhenghe_doctor_expr_stat.query(function(result) {
            $scope.d_m_zhenghe_doctor_expr_stats = result;
            angular.forEach($scope.d_m_zhenghe_doctor_expr_stats,function (data,index) {
                $scope.labels2[index]= data.dept_name;
                $scope.data2[0][index]=data.exp1t5_doctors;
                $scope.data2[1][index]=data.exp5t10_doctors;
                $scope.data2[2][index]=data.exp10t20_doctors;
                $scope.data2[3][index]=data.exp20t30_doctors;
                $scope.data2[4][index]=data.exp30_doctors;
            });
        });
    }
    //医生临床经验 end

    //用户注册量 start
    $scope.d_m_zhenghe_user_stats = [];

    get3();
    $scope.labels3=[];
    $scope.data3=[
        [],
        []
    ];
    $scope.series3 = ['注册总量', '活跃量'];
    function get3() {
        D_m_zhenghe_user_stat.query(function(result) {
            $scope.d_m_zhenghe_user_stats = result;
            angular.forEach($scope.d_m_zhenghe_user_stats,function (data,index) {
                $scope.labels3[index]= data.index_type;
                $scope.data3[0][index]=data.male_users;
                $scope.data3[1][index]=data.female_users;
            });

        });
    }
    //用户注册量 end

    //用户活跃量 start
    $scope.d_m_zhenghe_act_user_stats = [];
    $scope.labels5=["话题量","问题量"];
    $scope.series5 = ["男性","女性"];
    $scope.data5=[
        [],
        []
    ];
    get4();

    function get4() {
        D_m_zhenghe_act_user_stat.query(function(result) {
            $scope.d_m_zhenghe_act_user_stats = result;
            angular.forEach($scope.d_m_zhenghe_act_user_stats,function (data,index) {
                $scope.data5[0][index]=data.topic_count;
                $scope.data5[1][index]=data.quest_count;
            });
        });
    }
    //用户活跃量 end

    //运营分析
//1.处方量统计
    getMedicalData();
    $scope.d_m_zhenghe_recipe_stat=[];
    $scope.labels4 =[];
    $scope.data4 = [[],[]];
    $scope.series4=["处方量"];


    function getMedicalData() {
        D_m_zhenghe_recipe_stat.query(function (result) {
            $scope.d_m_zhenghe_recipe_stat=result;
            angular.forEach($scope.d_m_zhenghe_recipe_stat,function (data,index) {
                $scope.labels4[index]=data.disease_name;
                $scope.data4[0][index]=data.recipe_count;
            })
        })
    }

//1.处方量统计 end


    //2.寻医问药统计
    getSeekRecopeData();
    $scope.d_m_zhenghe_seekrecipe_stat=[];

    $scope.labels = [];
    $scope.datasetOverride = [
        {
            label: "询问量",
            borderWidth: 1,
            type: 'bar'
        },
        {
            label: "解答量",
            borderWidth: 3,

            type: 'line'
        }
    ];
    $scope.data = [
        [],
        []
    ];

    function getSeekRecopeData() {
        D_m_zhenghe_seekrecipe_stat.query(function (result) {
            $scope.d_m_zhenghe_seekrecipe_stat=result;
            angular.forEach($scope.d_m_zhenghe_seekrecipe_stat,function (data,index) {
                $scope.labels[index]=data.month_id+"月";
                $scope.data[0][index]=data.quest_count;
                $scope.data[1][index]=data.answer_count;

            })
        })
    }
    //2.寻医问药统计 end





}




